<template>
  <div class="rooms-container">
    <div class="page-content-wrap">
      <div class="user-title">所有房间</div>
      <div class="rooms-list">
        <div class="item" v-for="item in rooms">
          <div class="left-wrap">
            <img v-if="item.photo"
                 :src="uploadServer +  '/upload/image/' +item.photo"
            />
          </div>
          <div class="right-wrap">
            <div class="name">{{ item.name }}</div>
            <div class="price">费用：{{ item.price }}元</div>
            <div class="three-list">
              <div class="three-item">
                <img src="../../assets/image/icon/zdrs.png" alt="">
                <div class="number-wrap">
                  <div class="title">最多容纳人数</div>
                  <div class="value">{{ item.people }}</div>
                </div>
              </div>
              <div class="three-item">
                <img src="../../assets/image/icon/cwsl.png" alt="">
                <div class="number-wrap">
                  <div class="title">床位数量</div>
                  <div class="value">{{ item.bedCount }}</div>
                </div>
              </div>

            </div>
            <div class="big-wrap">
              <img src="../../assets/image/icon/cwsl.png" alt="">
              <div class="number-wrap">
                <div class="title">床的大小</div>
                <div class="value">{{ item.bedSize }}</div>
              </div>
            </div>
            <div class="big-wrap">
              <img src="../../assets/image/icon/sb.png" alt="">
              <div class="number-wrap">
                <div class="title">设备</div>
                <div class="value">{{ item.equipment }}</div>
              </div>
            </div>
            <div class="big-wrap">
              <img src="../../assets/image/icon/byp.png" alt="">
              <div class="number-wrap">
                <div class="title">备用品</div>
                <div class="value">{{ item.spares }}</div>
              </div>
            </div>

            <div class="reserve-btn" @click="onClickReserve(item)">
              预定
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import $api from '@/api'
import {onMounted, ref} from "vue";
import router from "@/router";

const uploadServer = import.meta.env.VITE_SERVER
onMounted(() => {
  getRooms()
})
/**
 * 获取房间
 */
const rooms = ref([])
const getRooms = () => {
  $api.webApi.getRooms().then(res => {
    rooms.value = res
  })
}
/**
 * 点击预定
 */
const onClickReserve = (room: any) => {
  var rule = localStorage.getItem('rule')
  if (rule === 'USER' || rule === 'ADMIN' || rule === 'FRONT_USER') {
    router.push('/room-detail/' + room.id)
  } else {
    router.push('/login?redirect=/rooms')
  }
}
</script>

<style scoped lang="scss">
.rooms-container {
  width: 100%;
  min-height: 900px;
  background-color: #fff;
}

.rooms-list {
  width: 100%;

  > .item {
    width: 100%;
    display: flex;
    height: 430px;
    margin-bottom: 40px;

    > .left-wrap {
      width: 55%;
      height: 100%;

      > img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    > .right-wrap {
      background-color: #fafafa;
      width: 45%;
      height: 100%;
      padding-left: 40px;
      padding-right: 20px;
      padding-top: 10px;
      position: relative;

      > .name {
        color: #003a56;
        font-size: 30px;
        margin-bottom: 4px;
      }

      > .price {
        color: #3a3a3a;
        font-size: 20px;
        font-style: italic;
        line-height: 1.8;
        margin-bottom: 4px;
      }

      > .three-list {
        display: flex;
        align-items: center;
        margin-bottom: 10px;

        > .three-item {
          width: 33%;
          display: flex;

          > img {
            width: 40px;
            height: 40px;
            margin-right: 10px;
          }

          > .number-wrap {
            width: calc(100% - 50px);
            overflow: hidden;

            > .title {
              line-height: 1.8;
              color: #003a56;
              font-size: 16px;
              font-weight: bold;
            }

            > .value {
              font-size: 14px;
            }
          }
        }
      }

      > .big-wrap {
        display: flex;
        margin-bottom: 10px;

        > img {
          width: 40px;
          height: 40px;
          margin-right: 10px;
        }

        > .number-wrap {
          width: calc(100% - 50px);
          overflow: hidden;

          > .title {
            color: #003a56;
            font-size: 16px;
            font-weight: bold;
            line-height: 1.8;
          }

          > .value {
            font-size: 14px;
          }
        }
      }
    }
  }
}

.reserve-btn {
  width: 120px;
  height: 40px;
  background-color: #3a3a3a;
  position: absolute;
  bottom: 10px;
  right: 10px;
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.4s ease;

  &:hover {
    opacity: 0.75;
  }
}
</style>